package com.midcent.networklib.sftp.core;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.midcent.networklib.R;
import com.midcent.networklib.sftp.SftpUtils;

/**
 */
public abstract class Builder {
    public String src;
    public String dst;
    public String username;
    public String host;
    public String password;
    public int port;
    /**
     * GET[0]、PUT[1]
     */
    public int type;

    Context context;

    public Builder(Context context) {
        this.context = context;
    }

    public Builder src(String s) {
        if (!TextUtils.isEmpty(s)) {
            this.src = s;
        }
        return this;
    }

    public Builder dst(String d) {
        if (!TextUtils.isEmpty(d)) {
            this.dst = d;
        }
        return this;
    }

    public Builder username(String u) {
        if (!TextUtils.isEmpty(u)) {
            this.username = u;
        }
        return this;
    }

    public Builder host(String host) {
        if (!TextUtils.isEmpty(host)) {
            this.host = host;
        }
        return this;
    }

    public Builder password(String p) {
        if (!TextUtils.isEmpty(p)) {
            this.password = p;
        }
        return this;
    }

    public Builder port(int port) {
        if (port > 0) {
            this.port = port;
        }
        return this;
    }

    protected abstract int type();

    public SftpUtils build() {
        if (src == null || dst == null) {
            src = "test.txt";
            dst = "/home//userw/recording_files/test.txt";
        }

        if (username == null || host == null || password == null || port == 0) {
            username = "userr";
            host = "rec.mid-cent.com";
            password = "mid-Cent";
            port = 22;
            Log.d("Builder", "XXX " + username);
            Log.d("Builder", username);
            Log.d("Builder", host);
            Log.d("Builder", password);
            Log.d("Builder", "port:" + port);
        }

        type = type();

        SftpUtils s = SftpUtils.getInstance();
        s.setBuilder(this);
        return s;
    }


}
